package com.ruoyi.chengji.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pingjiao.domain.CourseclassTeacher;
import com.ruoyi.pingjiao.domain.Student;
import com.ruoyi.pingjiao.service.ICourseclassTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教师上课Controller
 * 
 * @author 牛亚博
 * @date 2023-07-08
 */
@RestController
@RequestMapping("/score/CourseclassTeacher")
public class CourseclassTeacherController extends BaseController
{
    @Autowired
    private ICourseclassTeacherService courseclassTeacherService;

    /**
     * 查询教师上课列表
     */
    @PreAuthorize("@ss.hasPermi('score:courseclassTeacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseclassTeacher courseclassTeacher)
    {
        startPage();
        List<CourseclassTeacher> list = courseclassTeacherService.selectCourseclassTeacherList(courseclassTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师上课列表
     */
    @PreAuthorize("@ss.hasPermi('score:courseclassTeacher:export')")
    @Log(title = "教师上课", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseclassTeacher courseclassTeacher)
    {
        List<CourseclassTeacher> list = courseclassTeacherService.selectCourseclassTeacherList(courseclassTeacher);
        ExcelUtil<CourseclassTeacher> util = new ExcelUtil<CourseclassTeacher>(CourseclassTeacher.class);
        util.exportExcel(response, list, "教师上课数据");
    }

    /**
     * 获取教师上课详细信息
     */
    @PreAuthorize("@ss.hasPermi('score:courseclassTeacher:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return AjaxResult.success(courseclassTeacherService.selectCourseclassTeacherByTeacherId(teacherId));
    }

    /**
     * 获取教师上课班级查询对应的学生信息
     */
//    @PreAuthorize("@ss.hasPermi('niuyabo:getCourseclassTeacherAndStudent:query')")
    @GetMapping(value = "/student/{courseclassId}")
    public TableDataInfo getStudentList(@PathVariable("courseclassId") Long courseclassId)
    {
        startPage();
        List<Student> list = courseclassTeacherService.selectCourseclassStudentList(courseclassId);
        return getDataTable(list);
//        return success(courseclassTeacherService.selectCourseclassTeacherByTeacherId(teacherId));
    }

    /**
     * 新增教师上课
     */
    @PreAuthorize("@ss.hasPermi('score:courseclassTeacher:add')")
    @Log(title = "教师上课", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseclassTeacher courseclassTeacher)
    {
        return toAjax(courseclassTeacherService.insertCourseclassTeacher(courseclassTeacher));
    }

    /**
     * 修改教师上课
     */
    @PreAuthorize("@ss.hasPermi('score:courseclassTeacher:edit')")
    @Log(title = "教师上课", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseclassTeacher courseclassTeacher)
    {
        return toAjax(courseclassTeacherService.updateCourseclassTeacher(courseclassTeacher));
    }

    /**
     * 删除教师上课
     */
    @PreAuthorize("@ss.hasPermi('score:courseclassTeacher:remove')")
    @Log(title = "教师上课", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(courseclassTeacherService.deleteCourseclassTeacherByTeacherIds(teacherIds));
    }
}
